/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package reyes.mysite.jdo;

import java.util.Date;
import java.util.List;
import com.google.appengine.api.datastore.Text;
import com.google.appengine.api.datastore.Key;
import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

/**
 *
 * @author reyesyang
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Blog {

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    @Persistent
    private String title;
    @Persistent
    private String nickTitle;
    @Persistent
    private String category;
    @Persistent
    private String privacy;
    @Persistent
    private Date date;
    @Persistent
    private Text summary;
    @Persistent
    private Text content;
    @Persistent
    private int readCount;
    @Persistent
    private int commentCount;
    @Persistent(mappedBy = "blog",defaultFetchGroup="true")
    @Element(dependent = "true")
    private List<Comment> comments;

    public Blog(
            //Key key,
            String title,
            String category,
            String privacy,
            Date date,
            String summary,
            String content) {
        //this.key = key;
        this.title = title;
        this.nickTitle = title.replace(" ", "-").toLowerCase();
        this.category = category;
        this.privacy = privacy;
        this.date = date;
        this.summary = new Text(summary);
        this.content = new Text(content);
        this.readCount = 0;
        this.commentCount = 0;
    }

    public void setKey(Key key) {
        this.key = key;
    }

    public Key getKey() {
        return this.key;
    }

    public void setTitle(String name) {
        this.title = name;
    }

    public String getTitle() {
        return this.title;
    }

    public void setNickTitle(String nickTitle) {
        this.nickTitle = nickTitle;
    }

    public String getNickTitle() {
        return this.nickTitle;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getCategory() {
        return this.category;
    }

    public void setPrivacy(String privacy) {
        this.privacy = privacy;
    }

    public String getPrivacy() {
        return this.privacy;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Date getDate() {
        return this.date;
    }

    public void setSummary(String summary) {
        this.summary = new Text(summary);
    }

    public String getSummary() {
        return this.summary.getValue();
    }

    public void setContent(String content) {
        this.content = new Text(content);
    }

    public String getContent() {
        return this.content.getValue();
    }

    public void setReadCount(int readCount) {
        this.readCount = readCount;
    }

    public int getReadCount() {
        return this.readCount;
    }

    public void setCommentCount(int commentCount) {
        this.commentCount = commentCount;
    }

    public int getCommentCount() {
        return this.commentCount;
    }

    public void setComments(List<Comment> comments) {
        this.comments = comments;
    }

    public List<Comment> getComments() {
        return this.comments;
    }
}
